package com.lifang.framework.context.annotation;

import com.lifang.framework.beans.factory.config.BeanDefinitionRegistry;
import com.lifang.framework.context.AnnotationParser;
import lombok.extern.slf4j.Slf4j;

import java.lang.annotation.Annotation;

@Slf4j
public class ClassPathBeanDefinitionScanner extends ClassPathScanningCandidateComponentProvider {

    private final BeanDefinitionRegistry registry;

    public ClassPathBeanDefinitionScanner(BeanDefinitionRegistry registry) {
        this.registry = registry;
    }

    public void addIncludeFilter(Class<? extends Annotation> aClass, AnnotationParser annotationParser) {
        if (log.isDebugEnabled()) {
            log.debug("Enable Annotation {} Parser {}", aClass.getSimpleName(), annotationParser.toString());
        }
        this.includeFilters.put(aClass, annotationParser);
    }

    public void doScan(String... basePackages) {
        for (String basePackage : basePackages) {
            if (log.isDebugEnabled()) {
                log.debug("scan packages {}", basePackage);
            }
            registerBeanDefinition(basePackage);
        }
    }

    @Override
    protected BeanDefinitionRegistry getRegistry() {
        return registry;
    }
}
